package zhr.chapter7;

public class Example7_2 {
    public static void main(String[] args) {
        String s1 = new String("Java面向对象程序设计");
        String s2 = "面向对象";
        String s3 = "JavaScript";
        String result1 = "s2未找到";
        String result2 = "s3未找到";
        for (int i = 0; i < s1.length() - s2.length(); i++) {
            if (s1.substring(i, i + s2.length()).compareTo(s2) == 0) {//s1.startsWith(s2,i)
                result1 = "s2找到";
                break;
            }
        }
        for (int i = 0; i < s1.length() - s3.length(); i++) {//s1.startsWith(s3,i)
            if (s1.startsWith(s3, i)) {
                result2 = "s3找到";
                break;
            }
        }
        System.out.println(result1);
        System.out.println(result2);
    }
}
